#include "declarator_list.h"


/*struct declarator_list{
  struct declarator * decl;
  struct declarator_list *next;
};

struct declarator{
  char id[100];
  int mode;
  int type;
  int constant;
};
*/

 void ajouter_taille(struct taille *taille, int constant){
  struct taille *tmp = taille;
  if(tmp->taille == 0){
    tmp->taille = constant;
  }
  else{
    while(tmp->next != NULL){
      tmp = tmp->next;
    }
    tmp->next->taille = constant;
    tmp->next->next = NULL;
  }
}

void declarator_list_ajouter(struct declarator_list* l, struct declarator* decl ){
  if (l->decl == NULL){
    l->decl = malloc(sizeof(struct declarator));
    l->decl = decl;
    l->next = NULL;
  }
  else{
    struct declarator_list *tmp = l;
  while(tmp->next != NULL)
    tmp = tmp->next;
  tmp->next = malloc(sizeof(struct declarator_list));
  tmp->next->decl = decl;
  tmp->next->next = NULL;
  }
}


void set_declarator_type(struct declarator * decl, int type){
  decl->type = type;
}


struct declarator_list* declarator_list_vide(){
  struct declarator_list * l = malloc(sizeof(struct declarator_list));
  l->decl = NULL;
  l->next = NULL;
}


void declarator_list_concat(struct declarator_list* l1, struct declarator_list* l2){
  if (l1->decl == NULL)
    l1 = l2;
  else {
    struct declarator_list *tmp = l1;
    while (tmp->next != NULL){
      tmp = tmp->next;
    }
    tmp->next = l2;
  }
}


void declarator_ajouter_tab(struct declarator* d, struct declarator_list * l){
  struct table_symbole *tab = tab_symb_vide(NULL, FONCTION);
  struct declarator_list *tmp = l;
  while (tmp->next != NULL){
    ajouter_var(tab, tmp->decl);
    tmp = tmp->next;
  }
  d->param_list = tab;
}
